import { makeAutoObservable } from "mobx";
import { light, dark } from "utils/theme/colors";
import { setStorage,getStorage } from "utils/storage"
import { ThemeString } from "utils/types"
import { themeMap } from "utils/constants" 


class ThemeStore {
  theme = light;

  constructor() {
    this.initializeTheme();
    makeAutoObservable(this);
  }

  async initializeTheme() {
    const storedTheme:ThemeString = await getStorage('theme');
    if(storedTheme){
      this.theme = themeMap[storedTheme];
    }
  }

  toggleTheme(theme:ThemeString) {
    const tTheme = themeMap[theme];
    this.theme = tTheme;
    setStorage('theme', theme);
  }
}

export default new ThemeStore();




